const express = require("express");
const path = require("path");
const {createProxyMiddleware}=require('http-proxy-middleware')
let app = express();

// 一旦遇到 /api的路由就会使用createProxyMiddleware 转发请求
app.use('/api',createProxyMiddleware({
    target:'http://localhost:4000',
    pathRewrite:{
        '^/api':''
    }
}))


app.get("/", (req, res) => {
  res.sendFile(path.join(__dirname, "./views/index.html"));
});

app.get("/getdata", (req, res) => {
  res.json({
    info: "我是3000端口下的数据",
  });
});
app.listen(3000);
